package com.course.controller;

import com.course.entity.ResultBody;
import com.course.service.EditDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/EditDetails")
@CrossOrigin(origins="*")
public class EditDetailsController {
    @Autowired
    private EditDetailsService editDetailsService;
    @RequestMapping("/EditDetailsUser")
    //编辑个人资料模块
    public ResultBody EditDetailsUser(@RequestBody Map<String,Object> map) {
        //判断参数是否正确
        if (map.get("usersex") == null || map.get("usercollege") == null || map.get("userclass") == null || map.get("userphone") == null || map.get("userpassword") == null || map.get("userage") == null || map.get("name") == null || map.get("usernumber") == null) {
            return new ResultBody(404, "缺少参数", false);
        }
//        //将对象类型进行转换成对应类型
//        Object priceObj = map.get("usersex");//用户性别女1，男2
//        String usercollege=(String)map.get("usercollege");//用户学院
//        String userclass=(String)map.get("userclass");//用户班级
//        String userphone=(String)map.get("userphone");//用户电话号码
//        String userpassword=(String)map.get("userpassword");//用户密码
//        Object priceObj1=map.get("userage");//用户年龄
//        String name=(String)map.get("name");//用户真实姓名1
//        String usernumber=(String)map.get("usernumber");
//        //将数值向下进行传送
//        Integer usersex;
//        Integer userage;
//        if (priceObj instanceof String) {
//            usersex = Integer.parseInt((String) priceObj);
//        } else if (priceObj instanceof Integer) {
//            usersex = (Integer) priceObj;
//        } else {
//            return new ResultBody(400, "性别格式错误", false);
//        }
//
//        if (priceObj1 instanceof String) {
//            userage = Integer.parseInt((String) priceObj1);
//        } else if (priceObj instanceof Integer) {
//            userage = (Integer) priceObj;
//        } else {
//            return new ResultBody(400, "年龄格式错误", false);
//        }

//        return editDetailsService.EditDetailsUser(usersex, usercollege, userclass, userphone, userpassword, userage, name,usernumber);
//    }
        return editDetailsService.EditDetailsUser(map);
    }
    @RequestMapping("/lookMessage")
    //查看个人信息模块
    public ResultBody lookMessage(@RequestBody Map<String,Object> map) {
        if(map.get("usernumber")==null){
            return new ResultBody(404,"缺少参数",false);
        }
        String usernumber=(String)map.get("usernumber");
        return editDetailsService.lookMessage(usernumber);
    }
}
